<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>

    <style>
        .travels img{
            width: 100%;
        }
    </style>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            var currentPage = 1;
            var pages;
            var travelArr = [];

            //封装成一个函数
            function query() {
                //查询所有的
                $.get("/users/" + user.id + "/travels", {currentPage: currentPage}, function (data) {
                    //从data中取出list数组合并在第一个给定的初始数组中
                    $.merge(travelArr, data.list);
                    var json = {
                        list: travelArr
                    };
                    //数据渲染完,跳转编辑页面是带上id和数据做回显功能
                    $('.travels').renderValues(json,{
                        getHref:function (item,value) {
                            $(item).attr("href", '/mine/editTravels.html?id=' + value);

                        }
                    });
                    pages = data.pages;
                });
                currentPage += 1;
            }

            query();

            //窗口滚动事件,判断是否到底页面底部,如果是,需要再判断是否超过总页数,不是才进行分页
            $(window).scroll(function () {
                if ($(window).height() + $(document).scrollTop()+1 >= $(document).height()) {
                    //如果是大于总页数就不发送请求
                    if (currentPage <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            content: '<span class="info-text">到底喽</span>',
                            autoClose: 2500  //2.5秒后自动关闭
                        })
                    }
                }
            });

        });

    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>


<div class="container travels ">
    <dl class="lists" render-loop="list">
        <dd>
            <a render-fun="getHref" render-key="list.id">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"></h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
                    <span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>
</body>
</html>
